﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JKF.Substructure
{
    public class SessionManager
    {
        public static object Get(string key)
        {
            var ss = System.Web.HttpContext.Current.Session;
            var obj = ss[key];
            if (obj == null)
            {
                System.Web.HttpContext.Current.Response.Redirect("~/Login.aspx");
                throw new Exception("需要登录");
            }
            else
            {
                return obj;
            }
        }

        public static bool Exist(string key)
        {
            return System.Web.HttpContext.Current.Session[key] != null;

        }

        public static void Set(string key, object val)
        {
            System.Web.HttpContext.Current.Session[key] = val;
        }

        public static void Clear()
        {
            var ss = System.Web.HttpContext.Current.Session;
            ss.RemoveAll();

            ss.Abandon();
        }
    }
}
